package org.meluk.billboard.game.seaBattle;

public enum GameState {

    CREATED(0, "org.meluk.billboard.game.seaBattle.CREATED"),
    SHIP_LOCATION(0, "org.meluk.billboard.game.seaBattle.SHIP_LOCATION"),
    PLAYING(2, "org.meluk.billboard.game.seaBattle.PLAYING"),
    SUSPENDED(3, "org.meluk.billboard.game.seaBattle.SUSPENDED"),
    FINISHED(4, "org.meluk.billboard.game.seaBattle.FINISHED");

    public static GameState fromId(final int id) {
        GameState[] types = GameState.values();
        for (GameState e : types) {
            if (e.id == id) {
                return e;
            }
        }

        throw new IllegalArgumentException(String.format(
                "GameState with id %s not found", id));
    }

    public static GameState fromLabel(final String label) {
        GameState[] types = GameState.values();
        for (GameState e : types) {
            if (e.label.equalsIgnoreCase(label)) {
                return e;
            }
        }

        throw new IllegalArgumentException(String.format(
                "GameState with label %s not found", label));
    }
    private final int id;
    private final String label;

    private GameState(final int id, final String label) {
        this.id = id;
        this.label = label;
    }

    public int getId() {
        return id;
    }

    public String getLabel() {
        return label;
    }

    @Override
    public String toString() {
        return id + ":" + label;
    }
}
